package com.tanhua.app.controller;

import com.tanhua.app.service.UserService;
import com.tanhua.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
@RestController
public class PhoneController {
    @Autowired
    private UserService userService;
    @PostMapping(value = "/users/phone/sendVerificationCode",name = "修改手机号：发送验证码")
    public ResponseEntity sendVerificationCode(){
        String phone = UserHolder.getUser().getPhone();
        return userService.login(phone);
    }
    @PostMapping(value = "/users/phone/checkVerificationCode",name = "修改手机号：检验验证码")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String, String> map){
        String  verificationCode = map.get("verificationCode");
        return userService.checkVerificationCode(verificationCode);
    }

    @PostMapping(value = "/users/phone",name = "修改手机号：保存手机号")
    public ResponseEntity savePhone(@RequestBody Map<String, String> map){
        String  phone = map.get("phone");
        return userService.savePhone(phone);
    }
}
